<!-- 对公账户设置 -->
<template>
    <div>
        <div class="table-page-search-wrapper">
            <a-form layout="inline">
                <a-row :gutter="48">
                    <a-col :md="16" :sm="24">
                    </a-col>
                    <a-col :md="4" :sm="24">
                        <a-form-item >
                            <a-button type="primary" @click="getAccount()">查询</a-button>
                        </a-form-item>
                    </a-col>
                </a-row>
            </a-form>
        </div>
        <a-tabs
            :activeKey="customActiveKey"
            :tabBarStyle="{  borderBottom: 'unset' }"
            @change="handleTabClick"
        >
            <a-tab-pane v-for="(type,i) in evidenceTypeListInit" :key="i" :tab="type.name" :closable="false">
                <a-form :label-col="{ span: 4 }" :wrapper-col="{ span: 14 }">
                    <a-form-item v-if="customActiveKey == 0" label="企业名称">
                        <a-input v-model="account.accountName" placeholder="请输入支付宝企业名称" allow-clear></a-input>
                    </a-form-item>
                    <a-form-item :label="customActiveKey != 0 ? '充币地址' : '支付宝账号'">
                        <a-input v-model="account.account" :placeholder="customActiveKey != 0 ? '请输入充币地址' : '请输入支付宝账号'" allow-clear></a-input>
                    </a-form-item>
                    <!-- <a-form-item :label="customActiveKey != 0 ? '充值APP' : '开户银行'">
                        <a-input v-model="account.bankName" :placeholder="customActiveKey != 0 ? '请输入充值APP' : '请输入开户银行'" allow-clear></a-input>
                    </a-form-item> -->
                    <a-form-item :wrapper-col="formTailLayout.wrapperCol">
                        <a-button type="primary" @click="update">保存</a-button>
                        <a-popconfirm
                            v-if="account.id"
                            title="是否确认删除当前数据?"
                            ok-text="Yes"
                            cancel-text="No"
                            @confirm="del(account)"
                            style="margin-left: 50px"
                        >
                            <a-button type="danger" ghost>删除</a-button>
                        </a-popconfirm>
                    </a-form-item>
                </a-form>
            </a-tab-pane>
        </a-tabs>
    </div>
</template>

<script>
const formTailLayout = {
    labelCol: { span: 4 },
    wrapperCol: { span: 8, offset: 4 },
};
import { queryBrandTopUpAccount , updateBrandTopUpAccount } from '@/api/brand';
export default {
    data () {
        return {
            brandId: this.global.brandId,
            brandList: [],
            evidenceType: '', // 账户类型
            evidenceTypeListInit: [
                   { id: '1', name: '支付宝账户配置'},
                // { id: '1', name: 'CNY充值账户'},
                // { id: '2', name: 'FIL充值账户'},
                // { id: '3', name: 'XCH充值账户'},
            ],
            customActiveKey: 0,
            accountInit: {
                id: undefined,
                account: '', // 充币地址，开户银行
                accountName: '', // 账户姓名，开户姓名
                bankName: '', // 开户银行
                remark: '', // 提示
            },
            account: {},
            formTailLayout,
        };
    },
    created(){
        this.getAccount()
    },
    methods: {
        // 查询对公账户信息
        getAccount(){
            let _this = this
            _this.account = JSON.parse(JSON.stringify(_this.accountInit))
            const params = {
                'brandId':_this.brandId,
                'evidenceType':_this.evidenceTypeListInit[_this.customActiveKey].id
            }
            queryBrandTopUpAccount(params)
            .then(res=>{
                if(res.success){
                    if(res.data.content.length > 0){
                        _this.account = res.data.content[0]
                    }
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        // 选择充值账户
        handleTabClick(key){
            this.customActiveKey = key
            console.log(key)
            this.getAccount()
        },
        // 保存对公账户信息
        update(){
            let _this = this
            if(!_this.brandId){
                this.$message.warning('请先选择品牌！');
                return
            }
            if(_this.account.account == ''){
                this.$message.warning(_this.customActiveKey == 0 ? '请输入银行卡号信息' : '请输入充币地址');
                return
            }
            if(_this.customActiveKey == 0){
                if(_this.account.accountName == ''){
                    this.$message.warning('请输入账户姓名');
                    return
                }
                if(_this.account.bankName == ''){
                    this.$message.warning('请输入开户银行信息');
                    return
                }
            }
            const params = {
                'brandId':_this.brandId,
                'id':_this.account.id,
                'account':_this.account.account,
                'accountName':_this.account.accountName,
                'bankName':_this.account.bankName,
                'evidenceType':_this.evidenceTypeListInit[_this.customActiveKey].id,
            }
            updateBrandTopUpAccount(params)
            .then(res=>{
                if(res.success){
                    _this.$notification['success']({
                        message: '提示',
                        description: _this.account.id ? '修改成功' : '添加成功',
                        duration: 8,
                    })
                    _this.handleTabClick(_this.customActiveKey)
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        // 删除信息
        del(item){
            let _this = this
            const params = {
                'id':item.id,
                'isDelete': 1,
            }
            updateBrandTopUpAccount(params)
            .then(res=>{
                if(res.success){
                    _this.$notification['success']({
                        message: '提示',
                        description: '删除成功',
                        duration: 8,
                    })
                    _this.handleTabClick(_this.customActiveKey)
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
    }
}

</script>
<style scoped>

</style>